﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Net.Sockets;
using System.Net;
using System.Threading;

namespace Snake.Model
{
    class Connexion
    {
        private string type;

        private Client Cl;
        private Serveur Serv;


        //private bool ConnexionOk = false;
        public Serveur serveur
        {
            get { return this.Serv; }
            set { this.Serv = value; }
        }

        public Client client
        {
            get { return this.Cl; }
            set { this.Cl = value; }
        }

        public void Serveur(snake snake)
        {

            Serv = new Serveur(snake);
        }

        public void Client(string ip)
        {
            Cl = new Client(ip);
        }


        public Connexion(string type)
        {

            this.type = type;
        }

        public void EndConnexion()
        {
            //c'est mieux quand on lui dis d'arrété d'écouter mon loulou.
            if (this.type == "Serveur")
            { this.Serv.EndServ(); }
            else if (this.type == "Client")
            { this.Cl.Endclient(); }
            else
            {
               System.Windows.Forms.MessageBox.Show("Arret des threads non realiser");      
            }
          
        }

    /*    public void RecevoirNom()
        {
            Boolean ecouter=true;
            do
            {
                byte[] buffer = new byte[256];
                int recCount = 0;

                recCount = ListenSocket.Receive(buffer);
                Console.WriteLine(Encoding.UTF8.GetString(buffer, 0, recCount));
                Thread.Sleep(1000);
            } while (ecouter);

        }*/
    }
}
